#include "MovingIsle.h"

MovingIsle::MovingIsle(GameState *gameState, 
							const b2Vec2 &start,
							const b2Vec2 &end,
							const float size) : 
							Isle(gameState, size),
							m_start(start),
							m_end(end)
							{
	deleteProperty("Isle");
	addProperty("MovingIsle");
	m_texture = gameState->getTextureManager().getTexture("frozenIsle1.png");
	getFixtureDef(0)->friction = 10;
	m_state = 0;
	m_vel = 3;
}


void MovingIsle::firstUpdate(){
	m_originalPos = getPosition();
}


void MovingIsle::update(double dt){
	
	m_time+=dt;

	b2Vec2 targetPos;

	if(m_state == 0){
		targetPos = m_end;
	}else if(m_state == 1){
		targetPos = m_start;
	}

	b2Vec2 difPos = targetPos-getPosition();
	float dist = difPos.Normalize();
	if(dist < 1){
		if(m_state == 0){
			m_state = 1;
		}else if(m_state == 1){
			m_state = 0;
		}
	}
	
	difPos *= m_vel;
	m_body->SetLinearVelocity(difPos);
}




